package com.zkca.xf.receiver;


import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import com.google.gson.Gson;
import com.tencent.android.tpush.XGPushBaseReceiver;
import com.tencent.android.tpush.XGPushClickedResult;
import com.tencent.android.tpush.XGPushRegisterResult;
import com.tencent.android.tpush.XGPushShowedResult;
import com.tencent.android.tpush.XGPushTextMessage;
import com.zkca.xf.model.javabean.xg.CustomContentBean;
import com.zkca.xf.ui.activity.technicalprotect.Dianhu_LActivity;
import com.zkca.xf.utils.LogUtil;

import org.json.JSONException;
import org.json.JSONObject;

public class XgMsgReceiver extends XGPushBaseReceiver {
    public static final String LogTag = "TPushReceiver";

    @Override
    public void onRegisterResult(Context context, int i, XGPushRegisterResult xgPushRegisterResult) {

    }

    @Override
    public void onUnregisterResult(Context context, int i) {

    }

    @Override
    public void onSetTagResult(Context context, int i, String s) {

    }

    @Override
    public void onDeleteTagResult(Context context, int i, String s) {

    }

    @Override
    public void onTextMessage(Context context, XGPushTextMessage xgPushTextMessage) {

    }

    @Override
    public void onNotifactionClickedResult(Context context, XGPushClickedResult message) {
//        Log.e("LC", "+++++++++++++++ 通知被点击 跳转到指定页面。");
//        NotificationManager notificationManager = (NotificationManager) context
//                .getSystemService(Context.NOTIFICATION_SERVICE);
//        notificationManager.cancelAll();
//        if (context == null || message == null) {
//            return;
//        }
//        String text = "";
//        if (message.getActionType() == XGPushClickedResult.NOTIFACTION_CLICKED_TYPE) {
//            // 通知在通知栏被点击啦。。。。。
//            // APP自己处理点击的相关动作
//            // 这个动作可以在activity的onResume也能监听，请看第3点相关内容
//
//            String customContent = message.getCustomContent();
////            if (customContent != null && customContent.length() != 0) {
////                Gson gson=new Gson();
////                CustomContentBean customContentBean = gson.fromJson(customContent, CustomContentBean.class);
////                String module = customContentBean.getModule();
////                if (module.equals("0002")){
////                    context.startActivity(new Intent(context, Dianhu_LActivity.class));
////                }
////            }
//
//
//
//
//            text = "通知被打开 :" + message;
//        } else if (message.getActionType() == XGPushClickedResult.NOTIFACTION_DELETED_TYPE) {
//            // 通知被清除啦。。。。
//            // APP自己处理通知被清除后的相关动作
//            text = "通知被清除 :" + message;
//        }
//        Toast.makeText(context, "广播接收到通知被点击:" + message.toString(),
//                Toast.LENGTH_SHORT).show();
//        // 获取自定义key-value
//
////        if (customContent != null && customContent.length() != 0) {
////            try {
////                JSONObject obj = new JSONObject(customContent);
////                LogUtil.e("12312",customContent);
////                // key1为前台配置的key
////                if (!obj.isNull("key")) {
////                    String value = obj.getString("key");
////                    LogUtil.e("12312", "get custom value:" + value);
////                }
////                // ...
////            } catch (JSONException e) {
////                e.printStackTrace();
////            }
////        }
//        // APP自主处理的过程。。。
//        Log.e(LogTag, text);
//        show(context, text);
    }
    private void show(Context context, String text) {
        Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
    }
    // 通知展示
    @Override
    public void onNotifactionShowedResult(Context context, XGPushShowedResult xgPushShowedResult) {
        if (context == null || xgPushShowedResult == null) {
            return;
        }
        String s = xgPushShowedResult.toString();
        LogUtil.e("收到通知",s);
    }
}
